package org.dromara.northstar.gateway.ctp;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import cn.hutool.core.lang.Assert;

public class CtpSettingsConstants {
	
	private CtpSettingsConstants() {}
	
	public static final String SYS_ENV = "SYSENV";
	
	public static final String CTP_BROKER_ID = System.getenv("NS_CTP_BROKER_ID");
	
	public static final String CTP_APP_ID = System.getenv("NS_CTP_APP_ID");
	
	public static final Set<String> CTP_HOSTS = new HashSet<>() {
		private static final long serialVersionUID = 1L;
		{
			Pattern ptn = Pattern.compile("(\\d{1,3}\\.){3}\\d{1,3}");
			String hosts = System.getenv("NS_CTP_HOSTS");
			if(StringUtils.isNotBlank(hosts)) {
				for(String host : hosts.split(",")) {
					String hostStr = host.trim();
					Assert.isTrue(ptn.matcher(hostStr).matches(), "不合法IP：" + hostStr);
					add(hostStr);
				}
			}
		}
	};
	
	public static final String CTP_MD_PORT = System.getenv("NS_CTP_MD_PORT");
	
	public static final String CTP_TD_PORT = System.getenv("NS_CTP_TD_PORT");
	
	public static final String CTP_AUTH_CODE = System.getenv("NS_CTP_AUTH_CODE");
}
